package org.douxiaoban.client.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import org.douxiaoban.client.R;
import org.douxiaoban.client.api.MailData;
import org.douxiaoban.client.api.MiniBlogItemData;

import java.util.ArrayList;

public class MailAdapter extends DoubanAdapter{
	
	public MailAdapter(Context context){
		super(context, new ArrayList<MailData>());
	}

	@Override
	public View getView(int position, View view, ViewGroup vGroup) {
		// TODO Auto-generated method stub
		if ( position > mList.size()){
			return view;
		} 
		LayoutInflater layoutInflater = LayoutInflater.from(mContext);
		view = layoutInflater.inflate(R.layout.mail_item, null);
		TextView mailTitle = (TextView)view.findViewById(R.id.mailTitle);
		TextView mailSender = (TextView)view.findViewById(R.id.mailSender);
		TextView mailPublic = (TextView)view.findViewById(R.id.mailPublicTime);
		TextView mailFromOrTo = (TextView)view.findViewById(R.id.flag);
		
		MailData mailData = (MailData) mList.get(position);
		
		if(mailData.mTitle.length() > 12){
			mailData.mTitle = mailData.mTitle.substring(0, 12);
			mailData.mTitle += "...";
		}
		mailTitle.setText(mailData.mTitle);
		
		if(mailData.mIsInbox){
			mailFromOrTo.setText("来自 >> ");
			mailSender.setText(mailData.mSenderName);
		}else{
			mailFromOrTo.setText("发往 >> ");
			mailSender.setText(mailData.mRecName);
		}
		if(mailData.mUnread){
			view.setBackgroundColor(Color.parseColor("#9FE2E3E3"));
		}
				mailPublic.setText(mailData.mPublicTime);
		return view;
	}
	
	
}